package com.freewater.parking.domain.parking;

import com.freewater.parking.domain.common.DomainEvent;
import com.freewater.parking.domain.common.PlateNumber;
import org.apache.commons.lang3.Validate;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 已出场事件
 */
public class CheckedOutEvent implements DomainEvent {
    /**
     * 车牌号
     */
    private final PlateNumber plateNumber;
    /**
     * 出场时间
     */
    private final LocalDateTime checkOutTime;
    /**
     * 入场时间
     */
    private final LocalDateTime checkInTime;

    public CheckedOutEvent(PlateNumber plateNumber,
                           LocalDateTime checkOutTime,
                           LocalDateTime checkInTime) {
        Validate.notNull(plateNumber, "车牌号不能为空");
        Validate.notNull(checkOutTime, "车辆出场时间不能为空");
        Validate.notNull(checkInTime, "车辆入场时间不能为空");
        this.plateNumber = plateNumber;
        this.checkOutTime = checkOutTime;
        this.checkInTime = checkInTime;
    }

    @Override
    public LocalDateTime occurAt() {
        return this.checkOutTime;
    }

    /**
     * 获取车牌号
     *
     * @return 车牌号
     */
    public PlateNumber getPlateNumber() {
        return plateNumber;
    }

    /**
     * 获取出场时间
     *
     * @return 出场时间
     */
    public LocalDateTime getCheckOutTime() {
        return checkOutTime;
    }

    /**
     * 获取入场时间
     *
     * @return 入场时间
     */
    public LocalDateTime getCheckInTime() {
        return checkInTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CheckedOutEvent that = (CheckedOutEvent) o;
        return Objects.equals(plateNumber, that.plateNumber) &&
                Objects.equals(checkOutTime, that.checkOutTime) &&
                Objects.equals(checkInTime, that.checkInTime);
    }

    @Override
    public int hashCode() {
        return Objects.hash(plateNumber, checkOutTime, checkInTime);
    }
}
